<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<title><?php echo ((isset($title) && ($title !== ""))?($title):get_system_config("system_name")); ?></title>
		<link href="/Public/Ins/css/bootstrap.min.css" rel="stylesheet">
		<link href="/Public/Ins/font-awesome/css/font-awesome.css" rel="stylesheet">
		<link href="/Public/Ins/css/animate.css" rel="stylesheet">
		<link href="/Public/Ins/css/plugins/toastr/toastr.min.css" rel="stylesheet">
		<link href="/Public/Ins/css/plugins/gritter/jquery.gritter.css" />
		<?php if(!empty($plugin["jquery-ui"])): ?><link rel="stylesheet" href="/Public/Ins/css/plugins/jQueryUI/jquery-ui-1.10.4.custom.min.css" />
	<link rel="stylesheet" href="/Public/Ins/css/plugins/nouslider/jquery.nouislider.css" rel="stylesheet"><?php endif; ?>

	<link rel="stylesheet" href="/Public/Ins/css/plugins/date-time/bootstrap-datetimepicker.css" />


		<link href="/Public/Ins/css/style.css" rel="stylesheet">
		<link href="/Public/Ins/css/xiaowei.css" rel="stylesheet">
		<link href="/Public/Ins/css/nprogress.css" rel="stylesheet">
		<script src="/Public/Ins/js/nprogress.js"></script>
		<link rel="stylesheet" href="/Public/Ins/css/plugins/nouslider/jquery.nouislider.css" rel="stylesheet"><link rel="stylesheet" href="/Public/Ins/css/plugins/date-time/bootstrap-datetimepicker.css" />
		
	</head>
	<script type="text/javascript">
	var upload_url = "<?php echo U('upload');?>";
	var del_url = "<?php echo U('del_file');?>";
	var app_path = "";
	var cookie_prefix = "<?php echo C('COOKIE_PREFIX');?>";
	var link_select = "<?php echo U('Popup/link_select');?>";
	
</script>

	<body class="<?php echo (CONTROLLER_NAME); ?>">
		<div class="shade"></div>
		<div class="form-group hidden" id="img_upload_container">
			<div id="img_upload">上传</div>
		</div>
		<nav class="navbar navbar-default row" role="navigation" id="top_menu">
			<!-- Brand and toggle get grouped for better mobile display -->
			<div class="navbar-header">
				<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-collapse-6">
					<span class="sr-only">Toggle navigation</span>
					<i class="fa fa-bars fa-lg"></i>
				</button>
				<div class="hidden-xs">
					&nbsp;
				</div>
				<a href="<?php echo U('index/index');?>" class="navbar-brand"><?php echo get_system_config("system_name");?></a>
			</div>
			<!-- Collect the nav links, forms, and other content for toggling -->
			<div class="collapse navbar-collapse" id="navbar-collapse-6">
				<ul class="nav navbar-nav navbar-right">
					<?php if(is_array($top_menu)): foreach($top_menu as $key=>$top_menu_vo): ?><a class="nav-app" href="#" url="<?php echo (get_nav_url($top_menu_vo['url'])); ?>" node="<?php echo ($top_menu_vo["id"]); ?>" onclick="click_top_menu(this)" ><i class="<?php echo ($top_menu_vo["icon"]); ?>"></i><?php echo ($top_menu_vo["name"]); ?>
						<?php if(!empty($badge_count[$top_menu_vo['id']])){ $html=''; $html='<span class="label label-danger">'.$badge_count[$top_menu_vo['id']].'</span>'; echo $html; } ?></a><?php endforeach; endif; ?>
					<a class="nav-app btn-danger" href="<?php echo U('public/logout');?>"><i class="fa fa-sign-out"></i>退出</a>
				</ul>
			</div><!-- /.navbar-collapse -->
		</nav>
		<div id="wrapper">
			<div class="sidebar navbar-static-side" id="sidebar">
				<div id="user_info" class="text-center hidden-xs"  >
					<span >当前用户：<?php echo (session('user_name')); ?></span>
				</div>
				<div id="nav_head" class="text-center" onclick="toggle_left_menu()">
					<span class="menu-text"><?php echo ($top_menu_name); ?></span>
					<b id="left_menu_icon" class="fa fa-angle-down pull-right"></b>
				</div>
				<?php echo W('Sidebar/left',array('tree'=>$left_menu,'badge_count'=>$badge_count));?>
			</div>
			<div id="page-wrapper" class="gray-bg">
				<div class="row wrapper border-bottom gray-bg">
					<div class="breadcrumbs" id="breadcrumbs">
						<ul class="breadcrumb">
							<li>
								<i class="fa fa-home home-icon"></i>
								<a href="/">Home</a>
							</li>
							<li>
								<?php echo ($top_menu_name); ?>
							</li>
						</ul><!-- .breadcrumb -->
					</div>
				</div>
				<div class="wrapper wrapper-content">
					
    <link href="/sap/demo.css" rel="stylesheet" type="text/css" />
    <script src="/sap/scripts/boot.js" type="text/javascript"></script>
    <style>
		table img{width: 40px}
	</style>
<body style="">    
  <div class='show-pic'><img /></div>
    <table style="width:100%;height:100%;" >
        <tr>
            <td >
           	
             	<span class='span'>   物料关键字:</span>  <input type="input" class='mini-textbox' id='key' name='key' style="width: 180px"/>
            
              <a class="mini-button" iconCls="icon-search" onclick="search()" style="margin-left: -9px"></a>
              	<input id="combo1" onValuechanged="change()" class="mini-combobox" style="width:320px;" textField="name" valueField="id" emptyText="请选择清单..."  url="/Shelves/getMylist" value=""  allowInput="true" showNullItem="true" nullItemText="请选择清单..."/><a class="mini-button" iconCls="icon-add" onclick="promptClick()"></a> 
   
   			选择平台:<input id="btnEdit1" class="mini-buttonedit" onbuttonclick="onButtonEdit" name="" textName=""/>   
      		   <a class="mini-button" iconCls="icon-downgrade" onclick="send()">通知上架</a>
            <br/><br/>
                <div id="grid1" class="mini-datagrid" style="width:100%;height:500px;" 
                    idField="id" multiSelect="true" showFilterRow="true"
                    url="goods/queryItemBygoodssearch" resultAsData="true" >
                    <div property="columns">
                        <div type="checkcolumn"></div>
                         <div header="物料编号" field="code" width="80px">
                         <input id="code" property="filter" class="mini-textbox" style="width:100%;" onvaluechanged="onFilterChanged"/>
                         </div>
                         <div header="物料名称" field="name"  width="200px">
                          <input id="name" property="filter" class="mini-textbox" style="width:100%;" onvaluechanged="onFilterChanged"/>
                         </div>
                          <div header="颜色" field="color"  width="50px">
                          <input id="color" property="filter" class="mini-textbox" style="width:100%;" onvaluechanged="onFilterChanged"/>
                          </div>
                          <div header="图片" field="img"  width="50px"></div>
                           <div header="标签" field="tag"  width="">
                            <input id="tag" property="filter" class="mini-textbox" style="width:100%;" onvaluechanged="onFilterChanged"/>
                           </div>
                          <div header="重量" field="weight"  width=""></div>
                    </div>
                </div>
            </td>
            <!--   <td style="width:60px;text-align:center;">
              
                <input type="button" value="添加全部" onclick="addAll()" style="width:80px;"/><br />
                <input type="button" value="移除全部" onclick="removeAll()" style="width:80px;"/><br />
                

            </td> -->
            <td>
                
            </td>
          
        </tr>
        <tr>
        <td><br/><a class='mini-button' onclick="adds()" style="width:80px;" >添加到清单</a>&nbsp;&nbsp;&nbsp; <a class='mini-button'  onclick="settag()" style="width:80px;">设置标签</a></td>
        
        <td ><br/></td>
        </tr>
    
    </table>    
    <div  style="right:0px; top:88px; position:absolute;border: 1px solid #3498db ;width: 20px;height: 80%;padding-top: 20%;padding-left: 2px;cursor: pointer;"id='right-menu'>点我查看清单 </div>
    <div style="right:20px; top:88px; position:absolute;display: none;z-index: 99999;background-color: #ffffff;box-shadow: -2px 10px 10px  #888888;-moz-box-shadow: -2px 10px 10px #888888;" id='qdan-show'>
                <div id="grid2" class="mini-datagrid" style="width:600px;height:500px;border: 1px solid gray"                     
                    idField="id"  multiSelect="true" showPager="false" 
                    allowCellEdit="true" allowCellSelect="true" 
                >
                    <div property="columns">
                        <div type="checkcolumn"></div>
                         <div header="物料编号" field="code" width="80px"></div>
                         <div header="物料名称" field="name"  width="200px"></div>
                         <div header="颜色" field="color"  width="50px"></div>
                          <div header="图片" field="img"  width="50px"></div>
                          <div header="重量" field="weight"  width=""></div>
                            
                        </div>
                    </div>
                    &nbsp;<a class='mini-button' onclick="removes()" style="width:100px;">删除选中物料</a>  &nbsp;&nbsp;<a  href='javascript:void(0)' class='close_show' >关闭</a>
    </div>
    
    <script type="text/javascript">
	  jQuery('table img').live('hover',function(event){
		  
		  if(event.type=='mouseenter'){ 
			  jQuery(".show-pic img").attr('src',jQuery(this).attr('src'))
			  jQuery('.show-pic').css({'left':event.pageX+'px','top':'30%'})
			  jQuery(".show-pic").fadeIn(500);
			  }else{ 
					jQuery(".show-pic").hide();
			  }
		}
	  )
    $('#right-menu').toggle(function(){
    	$('#qdan-show').show();
    },
    function(){
    	$('#qdan-show').hide();
    }
    )
        jQuery('.close_show').click(function(){
    	 jQuery('#qdan-show').hide();
    })

    
          function onFilterChanged(e) {
            var namebox = mini.get("name");
            var codebox = mini.get("code");  
            var tagbox = mini.get("tag");  
            var name = namebox.getValue().toLowerCase();
 			var code = codebox.getValue().toLowerCase();
 			var tag  =tagbox.getValue().toLowerCase();
 			  var color = mini.get("color").getValue().toLowerCase();; 
            //多条件组合过滤
            grid1.filter(function (row) {
                //name
                var r1 = true;
                if (namebox) {
                    r1 = String(row.name).toLowerCase().indexOf(name) != -1;
                }

                var r2 = true;
                if (code) {
                    r2 = String(row.code).toLowerCase().indexOf(code) != -1;
                }
                
                var r3 = true;
                if (tag) {
                    r3 = String(row.tag).toLowerCase().indexOf(tag) != -1;
                }
                
                var r4 = true;
                if (color) {
                    r4 = String(row.color).toLowerCase().indexOf(color) != -1;
                }
                
                color
                return r1 && r2&& r3&&r4;
            });
        }
    
    
        mini.parse();
        var grid1 = mini.get("grid1");
        var grid2 = mini.get("grid2");
        grid1.on("drawcell", function (e) {
            var record = e.record,
                column = e.column,
                field = e.field,
                value = e.value;
            	if (field == "img") {
            		
            		 e.cellHtml="<img src='"+record.img+"' class='item-img'>";
          		  }

            });
        
        
        grid2.on("drawcell", function (e) {
            var record = e.record,
                column = e.column,
                field = e.field,
                value = e.value;
            	if (field == "img") {
            		
            		 e.cellHtml="<img src='"+record.img+"' class='item-img'>";
          		  }
            	
            });
        
        jQuery('.item-img').live('click',function(){
        	window.open(jQuery(this).attr('src'));
        })
   
        grid1.setPageSize(20);
        grid1.load();
        function search(){
        	var key = mini.get('key').getValue();
        	 grid1.load({'key':key});
        }
        function adds() {
        	
        	var id = mini.get('combo1').getValue();
        	if(id==''){
        	mini.alert('请选择清单');
        	return;
        	}
        	var data = new Object();
            var items = grid1.getSelecteds();
            grid1.removeRows(items);
            var selecteds = grid2.getData();
            var check=true;
            var dataIndex=0;
            for(var index=0;index<items.length;index++){
            	 for(var sindex=0;sindex<selecteds.length;sindex++){
                 		if(items[index].code==selecteds[sindex].code){
                 			check = false;
                 		}
                 }
            	 if(check){
            		 grid2.addRow(items[index]);
            		 data[dataIndex]=items[index];
            		 dataIndex++;
            	 }else{
            		 check = true;
            	 }
            }
           if(data.length==0)return;
           var postData = mini.encode(data);
            $.ajax({
                url: "/Shelves/saveShelvesDetailed",
                type: "post",
                data: { data:postData,pid:id },
                dataType:'json',
                success: function (data) {
                change();
                }
            });
            
            
        }
        function addAll() {
            var items = grid1.getData();       
            grid1.removeRows(items);
            grid2.addRows(items);
        }
        function removes() {
            var items = grid2.getSelecteds();
            var ids = '';
           	for(var index =0;index<items.length;index++){
           		ids+=items[index].id+",";
           	}
           	
            $.ajax({
                url: "/Shelves/delShelvesDetailed",
                type: "post",
                data: {ids:ids },
                dataType:'json',
                success: function (data) {
                }
            });
            grid2.removeRows(items);
          //  grid1.addRows(items);
        }
        function removeAll() {
            var items = grid2.getData();
            grid2.removeRows(items);
            grid1.addRows(items);
        }
        function upItem() {
            var items = grid2.getSelecteds();
            grid2.moveUp(items);
        }
        function downItem() {

            var items = grid2.getSelecteds();
            grid2.moveDown(items);
        }
        function saveData() {
            var data = grid2.getData();
            var json = mini.encode(data);
            alert(json);
        }
        
        function change(){
        
        	var id = mini.get('combo1').getValue();
        	if(id==''){
        		
        		return ;
        	}
        	loadingmsg('加载清单明细..')
        	
            $.ajax({
                 url: "/Shelves/getShelvesDetailed",
                 type: "post",
                 data: { pid: id },
                 dataType:'json',
                 success: function (data) {
                	 colseloading();
                	 grid2.setData(data);
                	 $('#qdan-show').show();
                 }
             });
        	
        }
        
        
        function promptClick() {
          var id = mini.get('btnEdit1').getValue();
          if(id==''){
        	  mini.alert('请选择平台');
        	  return;
          }

            mini.prompt("请输入清单名称：", "请输入",
                function (action, value) {
                    if (action == "ok") {
                    	if(value==''){
                    		mini.alert('名称不能为空');
                    		return;
                    	}
                    	saveshelvesList(value);
                    }

                }
            );
        }
        
        function saveshelvesList(name){
        	addlistData.name = name;

            $.ajax({
                 url: "/Shelves/saveshelvesList",
                 type: "post",
                 data: { savedata:mini.encode(addlistData) },
                 dataType:'json',
                 success: function (data) {
                	if(data.code!=0){
                		mini.alert('添加成功');
                		mini.get('combo1').setData(data.data);
                		mini.get('combo1').setValue(data.code);
                	} 
                	
                    
                 }
             });
        	
        }
        
        var addlistData = null;
        
        function onButtonEdit(e) {
            var btnEdit = this;
         
            mini.open({
                url:  "/Shelves/select",                          
                title: "选择平台",
                width: 650,
                height: 380,
                ondestroy: function (action) {
                  
                    if (action == "ok") {
                        var iframe = this.getIFrameEl();
                        var data = iframe.contentWindow.GetData();
                        data = mini.clone(data);
                        addlistData = data ;
                        data.listId = mini.get('combo1').getValue();
                        mini.get('btnEdit1').setText(data.text);
                        mini.get('btnEdit1').setValue(data.id);
                        
                    }
                }
            });            
             
        }  
        
        
        function send(){
        	var id = mini.get('combo1').getValue();
        	if(id==''){
        	mini.alert('请选择清单');
        	return;
        	}
        	loadingmsg('发送中....');
            $.ajax({
                url: "/Shelves/sendnotice",
                type: "post",
                data: { id:id },
                dataType:'json',
                success: function (data) {
                	  mini.unmask(document.body);
                   	  mini.alert(data.msg)
               	
                   
                }
            });
        }
        
        function settag(e) {
            var btnEdit = this;
            var rows = grid1.getSelecteds();
            if(rows.length==0){
            	mini.alert('请选择物料');return;
            }
            mini.open({
                url:  "/Shelves/selectTags",                          
                title: "选择标签",
                width: 650,
                height: 490,
                ondestroy: function (action) {
                  
                    if (action == "ok") {
                        var iframe = this.getIFrameEl();
                        var data = iframe.contentWindow.GetData();
                        data = mini.clone(data);
                        
                        dosetTag(data);
                        
                    }
                }
            });            
             
        } 
        
        
        function dosetTag(tags){
        	var rows = grid1.getSelecteds();
        	var ids = '';
        	for(var i=0;i<rows.length;i++){
        		ids+=rows[i].id+',';
        	}
        	ids = ids.substring(0,ids.length-1); 
            $.ajax({
                url: "/Shelves/setTag",
                type: "post",
                data: { ids:ids,tags:tags},
                dataType:'json',
                success: function (data) {
                	search();
                   
                }
            });
        	
        }
  
        
    </script>
</body>

				</div>
			</div>
		</div>
		<iframe src="<?php echo U('push/client');?>" class="push" id="push"></iframe>
		<!-- Mainly scripts -->
		<script src="/Public/Ins/js/jquery-2.1.1.js"></script>
		<script src="/Public/Ins/js/bootstrap.min.js"></script>
		<script src="/Public/Ins/js/plugins/metisMenu/jquery.metisMenu.js"></script>
		<script src="/Public/Ins/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
		

		<!-- Custom and plugin javascript -->
		<script src="/Public/Ins/js/inspinia.js"></script>
		<script src="/Public/Ins/js/common.js"></script>
		<script src="/Public/Ins/js/plugins/pace/pace.min.js"></script>
		<?php if(!empty($plugin["jquery-ui"])): ?><script src="/Public/Ins/js/plugins/jquery-ui/jquery-ui.min.js"></script>
	<script src="/Public/Ins/js/plugins/nouslider/jquery.nouislider.min.js"></script><?php endif; ?>

	<script src="/Public/Ins/js/plugins/date-time/moment-with-locales.js"></script>
	<script src="/Public/Ins/js/plugins/date-time/bootstrap-datetimepicker.js"></script>


<?php if(!empty($plugin["uploader"])): ?><script type="text/javascript" src="/Public/Ins/js/plugins/plupload/plupload.full.min.js"></script>
	<?php if(empty($plugin["auth"])): ?><script type="text/javascript" src="/Public/Ins/js/plugins/plupload/plupload.setting.js"></script><?php endif; endif; ?>

<?php if(!empty($plugin["editor"])): if(empty($plugin["uploader"])): ?><script type="text/javascript" src="/Public/Ins/js/plugins/plupload/plupload.full.min.js"></script><?php endif; ?>
	<script type="text/javascript" src="/Public/Ins/js/plugins/tinymce/tinymce.min.js"></script>
	<script type="text/javascript" src="/Public/Ins/js/plugins/tinymce/tinymce.setting.js"></script><?php endif; ?>

<?php if(!empty($plugin["baidu_map"])): ?><script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=EE6745c36d96321e90b7015f3de4a4ee"></script><?php endif; ?>

<script src="/Public/Ins/js/plugins/toastr/toastr.min.js"></script>
<script src="/Public/Ins/js/plugins/gritter/jquery.gritter.min.js"></script>
<script src="/Public/Ins/js/plugins/bootbox/bootbox.min.js"></script>

<script type="text/javascript">
	$(document).ready(function() {
		<?php if(!empty($plugin["date"])): ?>$('.input-date').datetimepicker({
			format : 'YYYY-MM-DD',
			locale : 'zh-cn',
			ignoreReadonly : true,
			widgetPositioning : {
				horizontal : 'auto',
				vertical : 'bottom'
			},
		});
		
		$(".input-daterange input").datetimepicker({
			format : "YYYY-MM-DD",
			locale : 'zh-cn',
			showTodayButton : true,
			showClose : true,
			ignoreReadonly : true,
			widgetPositioning : {
				horizontal : 'auto',
				vertical : 'bottom'
			},
		});

		$("#start_date").on("dp.change", function(e) {
			if ($("#end_date").length > 0) {
				$('#end_date').data("DateTimePicker").minDate(e.date);
			}
		});
		
		$("#end_date").on("dp.change", function(e) {
			if ($("#start_date").length > 0) {
				$('#start_date').data("DateTimePicker").maxDate(e.date);
			}
		});

		$(".input-date-time").datetimepicker({
			format : 'YYYY-MM-DD HH:mm',
			locale : 'zh-cn',
			sideBySide : true,
			showTodayButton : true,
			showClose : true,
			ignoreReadonly : true,
			widgetPositioning : {
				horizontal : 'auto',
				vertical : 'bottom'
			},
		});<?php endif; ?>		 
	}); 
</script>
		
	<script type="text/javascript">
		function save() {
			if ($("input:checked[name='user_id[]']").length < 1) {
				ui_error("请选择用户");
				return false;
			};

			var vars = $("#form_data").serialize();
			sendAjax("<?php echo U('save_user');?>", vars, function(data) {
				if (data.status) {
					ui_alert(data.info, function() {
						parent.location.reload(true);
						myclose();
					});
				}
			});

		}
	</script>

	</body>
</html>